package com.aistar.order.controller;

import com.aistar.common.util.IdWorker;
import com.aistar.common.vo.Result;
import com.aistar.order.entity.HotelOrder;
import com.aistar.order.entity.OrderInfo;
import com.aistar.order.service.IHotelOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * Created by Administrator on 2019/6/26 0026.
 */
@RestController
public class HotelOrderController {

    @Autowired
    private IHotelOrderService service;
    @Autowired
    private IdWorker idWorker;

//根据id找到具体的当前订单信息
    @GetMapping("/hotelorder/{id}")
    @ResponseBody
    public Result find (@PathVariable("id")String id){
        HotelOrder hotelOrder = service.findById(id);
        Result result= new Result(true,2000,"获取当前酒店信息",hotelOrder);
        return result;
    }
//根据页面信息增加订单
    @PostMapping("/hotelorder")
    @ResponseBody
    public Result save(HotelOrder hotelOrder){

        hotelOrder.setId(idWorker.nextId());
        hotelOrder.setCreateDate(new Date());
        hotelOrder.setOrderState("0");
        service.save(hotelOrder);
        Result result= new Result(true,2000,"增加订单信息",hotelOrder);
        return result;
    }
//    @PutMapping("/hotelorderu")
//    @ResponseBody
//    public Result update(HotelOrder hotelOrder, HttpSession session,@RequestParam("check") String check){
//        String checkcode_server = (String) session.getAttribute("CHECKCODE_SERVER");
//        session.removeAttribute(check); //防止验证码复用
//
//        if(!checkcode_server.equalsIgnoreCase(check)){
//             return new Result(false,5000,"验证码错误");
//        }else{
//
//        hotelOrder.setOrderState("1");
//        service.save(hotelOrder);
//        Result result= new Result(true,2000,"更新订单信息",hotelOrder);
//        return result;}
//
//    }
}
